package com.itheima.Array.sort;

/**
 * @Author: Ethan Yankang
 * @Program: code-random-recordings
 * @Date: 2024-08-19 13:27
 **/
public class SelectSort {
    public static void selectSort(int[] nums){
        int len= nums.length;
        for (int i = 0; i < len-1; i++) {
            int minIndex=i;
            for (int j = i; j < len; j++) {
                if (nums[j]<nums[i]){
                    minIndex=j;
                }
            }
            swap(nums,i,minIndex);
        }
    }

    private static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
